package com.future.lottie.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import com.airbnb.lottie.LottieAnimationView;
import com.future.lottie.R;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private LottieAnimationView mLottieAnimationView;
    private ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mLottieAnimationView = (LottieAnimationView) findViewById(R.id.lottie);
        mImageView = (ImageView) findViewById(R.id.iv_bg);


        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        final List<String> list = Arrays.asList("clear_day","clear_night",
                "cloudy_day","cloudy_night",
                "dust_day","dust_night",
                "fog_day","fog_night",
                "hail_day","hail_night",
                "haze","heavy_haze_day","heavy_haze_night",
                "heavy_rain_day","heavy_rain_night",
                "heavy_snow_day","heavy_snow_night",
                "light_haze_day","light_haze_night",
                "light_rain_day","light_rain_night",
                "moderate_haze_day","moderate_haze_night",
                "moderate_snow_day","moderate_snow_night",
                "partly_cloudy_day","partly_cloudy_night",
                "sand_day","sand_night",
                "sleet_day","sleet_night",
                "snow_day","snow_night",
                "storm_rain_day","storm_rain_night",
                "storm_snow_day","storm_snow_night",
                "thunder_shower_day","thunder_shower_night",
                "wind_day","wind_night");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,list);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String sky = list.get(position);
                showSkyconAnim(sky);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

//        Window window = getWindow();
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            int option = window.getDecorView().getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
//            window.getDecorView().setSystemUiVisibility(option);
//            window.setStatusBarColor(Color.TRANSPARENT);
//        }
    }
    private void showSkyconAnim(String skyconName) {


        String imageFolder = "background/" + skyconName;
        String fileName = "background/" + skyconName + ".json";

        String imageBg = String.format("zx_low_%s", skyconName);
        int identifier = getResources().getIdentifier(imageBg, "mipmap", getPackageName());

        mImageView.setImageResource(identifier);

        mLottieAnimationView.setImageAssetsFolder(imageFolder);
        mLottieAnimationView.setAnimation(fileName);


        mLottieAnimationView.setRepeatCount(-1);
        mLottieAnimationView.playAnimation();
    }




    public void drawer(View view) {
        startActivity(new Intent(this, DrawerActivity.class));
    }

    public void openSetting(View view) {
        Intent intent1 = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
        intent1.setData(Uri.parse("package:" + getPackageName()));
        intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent1);
    }
}
